#include "tetris_table.h"
namespace Tetris{

Tetris_Table::Tetris_Table(int left,int top,UI::UI_Window* parent): UI::UI_Window(UI::UI_Rect(left,top,left + 1,top + 1),parent){
	this->SetBackground("data/image/table.png");
}

void Tetris_Table::DrawCurrentTable(const Table_State* p_state){	
	if(!p_state) return;
	int x_start = 6;
	int y_start = 505;
	this->ClearSurface();
	UI::KTV_Draw* p_draw = UI::UI_Application::Instance()->GetDrawTextObj();
	for(int i=0;i<Table::ROW;++i){
		for(int j=0;j<Table::COL;++j){
			if(p_state->GetTable()->GetVal(j,i)){
				SDL_Surface* surface = p_draw->GetFromImageFile("data/image/color" + stdex::itoa(p_state->GetTable()->GetVal(j,i)) +".bmp");
				this->DrawSurface(surface,UI::UI_Point(x_start + j * Table::BLOCK_SIZE, y_start - (Table::ROW  - i) * Table::BLOCK_SIZE));
			}
		}
	}
}

}